package gtug.duesseldorf.client;

import gtug.duesseldorf.client.model.ClientCommand;

import java.io.Serializable;
import java.util.List;

import com.allen_sauer.gwt.log.client.Log;

import net.zschech.gwt.comet.client.CometListener;

public abstract class WaveServiceListener implements CometListener {
	// public abstract class WaveServiceListener implements RemoteEventListener {

	// @Override
	// public void apply(Event event) {
	// if (event instanceof ClientCommand) {
	// ClientCommand cc = (ClientCommand) event;
	// process(cc);
	// }
	// }

	public void onConnected(int heartbeat) {
		Log.info("WaveServiceListener::onConnected() heartbeat=" + heartbeat);
	}

	public void onDisconnected() {
		Log.info("WaveServiceListener::onDisconnected()");
	}

	public void onHeartbeat() {
		Log.info("WaveServiceListener::onHeartbeat()");
	}

	public void onError(Throwable exception, boolean connected) {
		Log.info("WaveServiceListener::onError() connected=" + connected + " ex=" + exception.getLocalizedMessage());
	}

	public void onMessage(List<? extends Serializable> messages) {
		for (Serializable message : messages) {
			process((ClientCommand) message);
		}
	}

	protected abstract void process(ClientCommand cc);

}
